package com.xpsoft.oa.service.produce.impl;


import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;

import com.xpsoft.core.service.impl.BaseServiceImpl;
import com.xpsoft.core.util.ContextUtil;
import com.xpsoft.oa.dao.produce.ArticleReceiveDao;
import com.xpsoft.oa.dao.produce.ArticleRegDao;
import com.xpsoft.oa.dao.produce.ArticleSendDao;
import com.xpsoft.oa.model.produce.ArticleReceive;
import com.xpsoft.oa.model.produce.ArticleReg;
import com.xpsoft.oa.model.produce.ArticleSend;
import com.xpsoft.oa.service.produce.ArticleRegService;

public class ArticleRegServiceImpl extends BaseServiceImpl<ArticleReg> implements ArticleRegService{
	private ArticleRegDao dao;
	@Autowired
	private ArticleReceiveDao articleReceiveDao;
	@Autowired
	private ArticleSendDao articleSendDao;
	public ArticleRegServiceImpl(ArticleRegDao dao) {
		super(dao);
		this.dao=dao;
	}

	@Override
	public void saveArticleReg(ArticleReg articleReg,
			ArticleReceive articleReceive, ArticleSend articleSend) {
		// TODO Auto-generated method stub
	    dao.save(articleReg);
	    if("收文".equals(articleReg.getArticleType())){
	    	articleReceive.setCreateTime(new Date());
	    	articleReceive.setCreateUser(ContextUtil.getCurrentUser());
	    	articleReceive.setArticleReg(articleReg);
	    	articleReceiveDao.save(articleReceive);
	    }else if("发文".equals(articleReg.getArticleType())){
	    	articleSend.setCreateTime(new Date());
	    	articleSend.setCreateUser(ContextUtil.getCurrentUser());
	    	articleSend.setArticleReg(articleReg);
	    	articleSendDao.save(articleSend);
	    }
	}

}